/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MenuControl2.java
 *
 * Created on 19/Jan/2012, 11:39:42
 */
package desint;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JOptionPane;
import popup.ControlEntrada2;

/**
 *
 * @author lenny
 */
public class MenuControl2 extends javax.swing.JPanel {

    
    JanelaPrincipal jp;
    
    /** Creates new form MenuControl2 */
    public MenuControl2() {
        initComponents();
        
        tabela.setAutoCreateRowSorter(true);
        
    }

    public void setJanelaPrincipal(JanelaPrincipal jp){
        this.jp = jp;
        saida.setEnabled(false);
        checkCell();
        
    }
    
      public void checkCell(){
        tabela.addMouseListener(new MouseAdapter() { 
          public void mousePressed(MouseEvent me) { 
            selectedCell();
          } 
        }); 
    }
    
    private void selectedCell() {

        Object val = tabela.getSelectedRows();
        if (val != null) {
            saida.setEnabled(true);
        } else {
            saida.setEnabled(false);
        }
    }
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        tabela = new javax.swing.JTable();
        saida = new javax.swing.JButton();
        entrada = new javax.swing.JButton();

        setBackground(new java.awt.Color(255, 255, 255));

        tabela.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"13", "Fernando Alonso", "socio"},
                {"15", "Johny Depp", "socio"},
                {"23", "Afonso Alberto", "treinador"},
                {"19", "Joana Linda", "treinador"}
            },
            new String [] {
                "Nº Socio", "Nome", "Perfil"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabela.setDragEnabled(true);
        tabela.getTableHeader().setReorderingAllowed(false);
        jScrollPane2.setViewportView(tabela);

        saida.setText("saida");
        saida.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                saidaMouseClicked(evt);
            }
        });

        entrada.setText("entrada");
        entrada.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                entradaMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 720, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(68, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(525, Short.MAX_VALUE)
                .addComponent(entrada)
                .addGap(54, 54, 54)
                .addComponent(saida)
                .addGap(105, 105, 105))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(60, 60, 60)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(saida)
                    .addComponent(entrada))
                .addContainerGap(80, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void saidaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saidaMouseClicked
        JOptionPane.showMessageDialog(null, "Saida Efetuada", "Saida", JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_saidaMouseClicked

    private void entradaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_entradaMouseClicked
        ControlEntrada2 novo = new ControlEntrada2(null, true);
        novo.setLocation(100, 100);
        novo.setVisible(true);
    }//GEN-LAST:event_entradaMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton entrada;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton saida;
    private javax.swing.JTable tabela;
    // End of variables declaration//GEN-END:variables
}
